package com.concurrency.example.visitor;

import java.util.Collection;
import java.util.Iterator;

/**
 * 混合访问
 */
public class ConcreteVisitor implements Visitor{
    /**
     * 访问字符串
     *
     * @param stringElement
     */
    @Override
    public void visitString(StringElement stringElement) {
        System.out.println(stringElement.getSe());
    }

    /**
     * 访问浮点数
     *
     * @param floatElement
     */
    @Override
    public void visitFloat(FloatElement floatElement) {
        System.out.println(floatElement.getFe());
    }

    /**
     * 访问集合
     *
     * @param collection
     */
    @Override
    public void visitCollection(Collection collection) {
        Iterator iterator = collection.iterator();

        while (iterator.hasNext()){
            Object next = iterator.next();
            if (next instanceof Visitable){
                ((Visitable)next).accept(this);
            }
        }
    }
}
